<?php
if (!isset($model))
    $model = new BDynamicFormModel ();

$BuyerIdField = 'media_buyerId_priceConfig_buyer';
$buyerCategoryField = 'media_buyerCategory_priceConfig_buyer';
$model->addField($BuyerIdField);
$model->addField($buyerCategoryField);

$priceConfigBuyerView = array();

if ($orderPriceConfigId > 0) {
    $priceConfigTable = new BPSheet('priceConfig');
    $priceConfig = $priceConfigTable->getListById($orderPriceConfigId);

    $priceConfigBuyerTable = new BPSheet('priceConfigBuyer', $priceConfig);
    $priceConfigBuyerView = $priceConfigBuyerTable->getView();
}
?>
<?php
$app = Blyn::app()->getActiveApp();
?>
<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "addPriceConfigForm",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
?>
<div class="well-small row-fluid">
    <div class="input-prepend span4">
        <span class="add-on">买家ID</span>
        <?php
        echo CHtml::activeTextField($model, $BuyerIdField, array('placeholder' => 'buyerId' . '...', 'required' => true, 'class' => 'span9'));
        ?>
        
    </div>
    <div class='span1'>-or-</div>
    <div class="input-prepend span5">
        <span class="add-on">买家分类</span>
        <?php
        echo CHtml::activeTextField($model, $buyerCategoryField, array('placeholder' => 'buyerCategory' . '...', 'required' => true, 'class' => 'span8'));
        ?>
    </div>
    <div class="input-append span2">
        <?php
        echo $control->getAjaxLink(array('name' => '添加买家', 'id' => 'addPriceConfigBuyer'), array(
            'htmlOptions' => array('class' => 'btn'),
            'orderPriceConfigId' => $orderPriceConfigId,
            'eventId' => $eventId,
        ));
        ?>
    </div>
</div>
<table class="table table-hover">
    <colgroup>
        <col class="span2">
        <col class="span4">
        <col class="span4">
    </colgroup>
    <thead>
        <tr>
            <th><?php echo '类型'; ?></th>
            <th><?php echo 'ID'; ?></th>
            <th><?php echo '操作'; ?></th>
        </tr>
    </thead>
    <tbody>
        <?php
        if ($orderPriceConfigId > 0) {
            foreach ($priceConfigBuyerView as $priceConfigBuyer) {
                $buyerConfigId = $priceConfigBuyer->getId();
                ?>
                <tr>
                    <?php
                    $buyerIdItem = $priceConfigBuyer->getItem('buyerId');
                    $buyerCategoryItem = $priceConfigBuyer->getItem('buyerCategory');
                    $buyerId = '';
                    $categoryId = '';
                    $type = '';
                    if ($buyerIdItem instanceof BTreeItem) {
                        $buyerId = $buyerIdItem->getValue();
                        $type = 'BuyerId';
                        ?>
                        <td> <?php echo $type; ?>  </td>   
                        <td> <?php echo $buyerId; ?>  </td>   
                    <?php } ?>
                    <?php
                    if ($buyerCategoryItem instanceof BTreeItem) {
                        $buyerCategory = $buyerCategoryItem->getValue();
                        $type = 'BuyerCategory';
                        ?>
                        <td> <?php echo $type; ?>  </td>   
                        <td> <?php echo $buyerCategory; ?>  </td>   
                    <?php } ?>
                    <td>
                        <?php
                        echo $control->getAjaxLink(array('name' => '删除', 'id' => 'deletePriceConfigBuyer'), array(
                            'htmlOptions' => array('class' => 'btn'),
                            'orderPriceConfigId' => $orderPriceConfigId,
                            'buyerConfigId' => $buyerConfigId
                        ));
                        ?>
                    </td>
                </tr>
                <?php
            }
        }
        ?>
    </tbody>
</table>
<?php
$this->endWidget();
//echo CHtml::endForm();
?>
